package com.zdj.presentation.app;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;

import com.zdj.data.net.UDPProxy;
import com.zdj.presentation.R;
import com.zdj.utils.MD5;

import static com.lkskt.frame.jni.Liblksjni.SS_LOGIN;

public class UdpService extends Service {

    private Handler mHandler = new Handler(Looper.myLooper()){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    };

    public UdpService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initData();
    }

    private void initData() {
        UDPProxy.initUDP(mHandler,getApplicationContext().getResources().getString(R.string.udp_ip));
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {


        if(intent != null){
            int cmd = intent.getIntExtra("cmd",0);
            switch (cmd){
                case SS_LOGIN:
                    login("15656969193", MD5.getMD5Code("123456"));
                    break;
            }
        }



        return super.onStartCommand(intent, flags, startId);
    }


    private void login(String username,String password){
        UDPProxy.login(username,password,"",0);
    }
}
